package com.wzh.himalaya.utils;

import com.wzh.himalaya.base.BaseFragment;
import com.wzh.himalaya.fragments.HistoryFragment;
import com.wzh.himalaya.fragments.RecommendFragment;
import com.wzh.himalaya.fragments.SubscriptionFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * className:FragmentCreator
 * Author:WZH
 * Time:2022-02-14
 */
public class FragmentCreator {

    public final static int PAGE_COUNT = 3; //三页

    public final static int INDEX_RECOMMEND =0;
    public final static int INDEX_SUBSCRIPTION =1;
    public final static int INDEX_HISTORY =2;

    private static Map<Integer, BaseFragment> sCache = new HashMap<>();

    public static BaseFragment getFragment(int index){
        BaseFragment baseFragment = sCache.get(index);
        if(baseFragment!=null)
        {
            return  baseFragment;
        }
        switch (index)
        {
            case INDEX_RECOMMEND:
                baseFragment = new RecommendFragment();
                break;
            case INDEX_SUBSCRIPTION:
                baseFragment = new SubscriptionFragment();
                break;
            case INDEX_HISTORY:
                baseFragment = new HistoryFragment();
                break;
        }

        sCache.put(index,baseFragment);
        return baseFragment;

    }
}
